<?php
	$TEMP->set_file(array('handle' => DIR_VIEW_DEAN . 'newCourse.html'));
	$CID 	= _GET('cid');
	
	if ( isset($_POST['subButton']) ) {
		
		$if_error	= 0;
		$txtcourse	= _POST('txtcourse');
		$txtmajor	= _POST('txtmajor'); 
		$txtcode	= _POST('txtcode'); 
		
		$link 		= time();
		
		if ( empty($txtcourse) )	{ $if_error++; $_txtcourse 	= REQ_FIELD; }
		if ( empty($txtcode) )		{ $if_error++; $_txtcode 	= REQ_FIELD; }
		
		if ( $if_error == 0 ) {
			
			$strArray = array('course' 	=> firstUpperCase($txtcourse),
							  'major' 	=> firstUpperCase($txtmajor),
							  'code' 	=> upperCase($txtcode),
							  'dept_id'	=> $strAccDept);
							  
			if ( empty($CID) )
				$DSC->insertCourse($strArray);
			else
				$DSC->updateCourse($strArray, $CID);
			
			redirect('?page=Course');
		}
	}
	else {
		if (!empty($CID)) {
			$getCourse = $DSC->getCourse($CID);
	
			$txtcourse 	= $getCourse['course_desc'];
			$txtmajor 	= $getCourse['course_major'];
			$txtcode 	= $getCourse['course_code'];
		}
	}
	
	
	$TEMP->set_var(array('dean_sub_menu'	=> $pageLib->deanSubMenu(DIR_IMAGES),
						 'w_txtcourse' 		=> $_txtcourse,
						 'w_txtmajor' 		=> $_txtmajor,
						 'w_txtcode' 		=> $_txtcode,
						 'txtcourse' 		=> $txtcourse,
						 'txtmajor' 		=> $txtmajor,
						 'txtcode' 			=> $txtcode,
						 'dept_course'		=> $strAccCourse,
						));
?>